package com.open.launcher.bean;

import android.os.Parcel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 栏目数据封装
 *
 * @author Richard
 */
public class Container extends Content {
    /**
     * 该栏目下有多少条数据
     */
    public int childCount;
    /**
     * 该栏目下热剧
     */
    public List<Item> topHots;
    /**
     * 该栏目下更新的影片
     */
    public List<Item> updates;
    /**
     * 该栏目下的栏目
     */
    public List<Container> containers;

    public Container() {
        this("", "", "", new ImageSource(), "");
    }

    public Container(String parentID, String contentID, String name, ImageSource imageSource, String type) {
        super(parentID, contentID, name, imageSource, type);
        topHots = new ArrayList<>();
        updates = new ArrayList<>();
        containers = new ArrayList<>();
    }

    // ---------------------Parcelable implements------------
    public static final Creator<Container> CREATOR = new Creator<Container>() {
        @Override
        public Container createFromParcel(Parcel source) {
            ArrayList<Item> topHots = new ArrayList<>();
            ArrayList<Item> updates = new ArrayList<>();
            ArrayList<Container> containers = new ArrayList<>();

            String parentID = source.readString();
            String contentID = source.readString();
            String name = source.readString();
            ImageSource imgSource = source.readParcelable(ImageSource.class.getClassLoader());
            String type = source.readString();
            Map extras = source.readHashMap(HashMap.class.getClassLoader());
            int childCount = source.readInt();
            source.readTypedList(topHots, Item.CREATOR);
            source.readTypedList(updates, Item.CREATOR);
            source.readTypedList(containers, Container.CREATOR);

            Container container = new Container(parentID, contentID, name, imgSource, type);
            container.extras = extras;
            container.childCount = childCount;
            container.topHots = topHots;
            container.updates = updates;
            container.containers = containers;
            return container;
        }

        @Override
        public Container[] newArray(int size) {
            return new Container[size];
        }

    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(parentID);
        dest.writeString(contentID);
        dest.writeString(name);
        dest.writeParcelable(imgSource, flags);
        dest.writeString(type);
        dest.writeMap(extras);
        dest.writeInt(childCount);
        dest.writeTypedList(topHots);
        dest.writeTypedList(updates);
        dest.writeTypedList(containers);
    }
}
